package com.blogspot.ostas.oracle.aq.spring;

import javax.jms.QueueConnectionFactory;

import oracle.jms.AQjmsSession;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Required;
 
public class OracleAqDestinationFactoryBean implements FactoryBean {
    private QueueConnectionFactory connectionFactory;
    private String queueName;
    private String queueUser;    
 
    @Required
    public void setConnectionFactory(QueueConnectionFactory connectionFactory) {
        this.connectionFactory = connectionFactory;
    }    
 
    @Required
    public void setQueueName(String queueName) {
        this.queueName = queueName;
    }    
 
    @Required
    public void setQueueUser(String queueUser) {
        this.queueUser = queueUser;
    }    
 
    public Object getObject() throws Exception {
        // createQueueSession(true,0) - create a transactional session
        AQjmsSession session = (AQjmsSession) connectionFactory.createQueueConnection().createQueueSession(false, 0);
        return session.getQueue(queueUser, queueName);
    }    
 
    public Class getObjectType() {
        return javax.jms.Queue.class;
    }    
 
    public boolean isSingleton() {
		return false;
    }
}
